<template>
  <div class="sidebar-container">
    <div class="logo">
      <transition name="fade-transform" mode="out-in">
        <div class="flex-center">
          <img class="logo-img" src="../../assets/logo-CRQ9AZN7.png" alt="logo"/>
          <label class="logo-text">ElementAdmin</label>
        </div>
      </transition>
    </div>
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <!-- 菜单栏     -->
      <el-menu :router="true"
               class="v-enter-to"
               :default-active="$route.path"
               :show-timeout="200"
               text-color="#fff"
               background-color="#4a5a74">
        <SidebarItem v-for="item in routerList" :key="item.path" :index="item.path" :nav="item"/>
      </el-menu>
    </el-scrollbar>
  </div>

</template>

<script lang="ts" setup>

import 'element-plus/dist/index.css'
import SidebarItem from '../Sidebar/SidebarItem.vue'
import {onBeforeUnmount, onMounted, reactive} from "vue";
import {constantRoutes} from "../../router";


const routerList: any[] = reactive([])

constantRoutes.forEach((item) => {
  if (item.path === '/main') {
    const children = item.children as any[]
    routerList.push(...children)
  }
})


</script>

<style lang="scss" scoped>

.router-checked {
  span {
    color: #001529;
  }

  i {
    color: #001529;
  }
}

.sidebar-container {
  width: 200px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1001;
  height: 95%;
  padding-top: 50px;
  overflow: hidden;
  font-size: 0;
  /* background-color: #4a5a74;*/
  background-color: #001529;
  transition: width 0.28s;

  // reset element-ui css
  .horizontal-collapse-transition {
    transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
  }

  .scrollbar-wrapper {
    overflow-x: hidden !important;
  }

  .el-scrollbar__bar.is-vertical {
    right: 0;
  }

  .el-scrollbar {
    height: 100%;
  }


  .is-horizontal {
    display: none;
  }

  a {
    display: inline-block;
    width: 100%;
    overflow: hidden;
  }

  .svg-icon {
    margin-right: 16px;
  }

  .sub-el-icon {
    margin-right: 12px;
    margin-left: -2px;
  }

  .el-menu {
    width: 100% !important;
    height: 100%;
    border: none;
  }


}

.logo {
  position: absolute;
  top: 0;
  display: flex;
  width: 100%;
  height: 50px;
  overflow: hidden;
  text-align: center;
  cursor: pointer;
  /*background-color: #ffffff;*/
  justify-content: center;
  align-items: center;
  background-color: #001529;

  .logo-img {
    width: 90%; /* width: 32px;*/
    height: 40px;
    position: relative;
    left: -75px;
  }

  .logo-text {
    width: 70%;
    display: inline-block;
    height: 50px;
    margin-left: 30px;
    font-size: 20px;
    line-height: 50px;
    color: #fff;
    position: absolute;
    top: 50%;
    left: 45%;
    transform: translate(-50%, -50%);
    /* 设置 z-index 值为 1，使其显示在图片上方 */
    //z-index: 1;
    font-weight: bold;
  }
}
</style>